#include "stdio.h"
#include "SDL/SDL.h"
void affichageFenetre();
int choixType();
int choix_symetrie();
int choix_cle();
void saisi_text();
void cryptagetext();
void decryptage();
void affichage_resultat();
void enregistrement();
void quitter();
int main(int argc, char** argv)
{
    SDL_Surface *fenetre2;
    SDL_Surface *fenetre1;
    SDL_Surface *fenetre3;
    SDL_Surface *screen;
    SDL_Event event;
    int numfenetre ;
    int done=1;
    SDL_Rect src,dest;

    freopen("CON","w",stdout);
    freopen("CON","r",stdin);

    // initialize SDL video
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("Unable to init SDL: %s\n", SDL_GetError());
        return (-1);
    }
    // create a new window
    screen = SDL_SetVideoMode(450, 441, 16, SDL_HWSURFACE | SDL_DOUBLEBUF|SDL_FULLSCREEN);
    if (!screen)
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return (-1);
    }
    SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
    fenetre1 = SDL_LoadBMP("fenetre1.bmp");
    fenetre2= SDL_LoadBMP("fenetre2.bmp");
    fenetre3= SDL_LoadBMP("fenetre3.bmp");
    src.x = 0;
    src.y = 0;
    src.w = fenetre1->w; //Use image->w to display the entire width of the image
    src.h = fenetre1->h; //Use image->h to display the entire height of the image
    dest.x = 0;//
    dest.y = 0;
    dest.w = fenetre1->w;
    dest.h = fenetre1->h;
    SDL_BlitSurface(fenetre1, &src, screen, &dest);
    numfenetre=1;
    SDL_Flip(screen);
    while(done)
    {


        if (numfenetre==1)
        {
            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                {
                case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;break;
                    case SDL_MOUSEBUTTONDOWN:
                        int x=event.motion.x;
                        printf("%d",x);
                        int y=event.motion.y;
                        if(x<295 && x>185 && y>362 && y<410)
                        {
                            SDL_BlitSurface(fenetre2, &src, screen, &dest);
                            SDL_Flip(screen);
                            numfenetre=2;
                            break;


                        }





                    }
                }
            }
        }
        if(numfenetre == 2)


        {
            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                { case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;break;
                case SDL_MOUSEBUTTONDOWN:
                    int x=event.motion.x;
                    printf("%d",x);
                    int y=event.motion.y;
                    if(x<282 && x>123 && y>318 && y<398)
                    {
                        SDL_BlitSurface(fenetre1, &src, screen, &dest);
                        SDL_Flip(screen);
                        numfenetre=1;



                    }if(x<125 && x>278 && y>51 && y<130)
                    {
                        SDL_BlitSurface(fenetre3, &src, screen, &dest);
                        SDL_Flip(screen);
                        numfenetre=3;
                }
                }
            }
        }







        }if(numfenetre == 3)

        {
            while(SDL_PollEvent(&event))
            {

                switch(event.type)
                {
                case SDL_QUIT:
                    done = 0;
                    break;
// check for keypresses
                case SDL_KEYDOWN:
                {
// exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = 0;break;
    }}}}}
    return 0;
}


